#include "bits/stdc++.h"
using namespace std;

const int maxn=1e5+10;
struct Node{
	int d;
	int v;
	int a;
}car[maxn];
int t,n,m,L,V,limit[maxn],ans1;
int specialA;

void A()
{
	ans1=0;
	int lmt=0;
	for(int i=1;i<=m;i++) lmt=max(lmt,limit[i]);
	for(int i=1;i<=n;i++)
		if(car[i].v>V&&car[i].d<=lmt) ans1++;
	if(ans1) cout<<ans1<<" "<<m-1<<endl;
	else cout<<ans1<<" "<<m<<endl;
}

int main()
{
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	cin>>t;
	while(t--)
	{
		specialA=0;
		scanf("%d%d%d%d",&n,&m,&L,&V);
		for(int i=1;i<=n;i++)
		{
			scanf("%d%d%d",&car[i].d,&car[i].v,&car[i].a);
			if(car[i].a!=0) specialA=1;
		}
		for(int i=1;i<=m;i++) scanf("%d",&limit[i]);
		if(!specialA) A();
	}
	return 0;
}
